import React, { Component } from 'react';

class App extends Component {
  render() {
    return (
      <div>
        <h1>App 组件</h1>
        <h2>{this.props.num}</h2>
      </div>
    );
  }
}
// connect(mapStateToProps,mapDispatchToProps)(App) => 返回一个新的组件
function connect(mapStateToProps,mapDispatchToProps){
  let props = mapStateToProps?mapStateToProps():{};// 默认注入的属性和方法都是空的
  let dispatchs = mapDispatchToProps?mapDispatchToProps():{};//
  return function(Cmp){
      return class extends Component{
        render(){
          return <Cmp {...props} {...dispatchs}></Cmp>
         
        }
      }
  }
}
export default connect(()=>{
  return {
    num: 666
  }
},()=>{
  return {
    add:function(){},
    sub:function(){}
  }
})(App);
